package com.sky.controller.admin;

import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品相关接口")
public class DishController {

    @Autowired
    private DishService dishService;
    @GetMapping("/page")
    @ApiOperation("分页查询分类")
    public Result<PageResult> findDishPageQuery(DishPageQueryDTO dishPageQueryDTO){
        log.info("获取的菜品查询信息是：{}",dishPageQueryDTO);
        PageResult categoryPageQuery = dishService.findDishPageQuery(dishPageQueryDTO);
        return Result.success(categoryPageQuery);
    }

    @PostMapping
    @ApiOperation("新增菜品")
    public Result addDish(@RequestBody DishDTO dishDTO){
        log.info("获取的菜品查询信息是：{}",dishDTO);
        dishService.addDish(dishDTO);
        return Result.success();
    }


   @GetMapping("/{id}")
    @ApiOperation("根据id查找菜品")
    public Result<DishVO> findDishById(@PathVariable Long id){
        log.info("获取的查询菜品的id信息是：{}",id);
       DishVO dishById = dishService.findDishById(id);
       return Result.success(dishById);
    }
    @DeleteMapping
    @ApiOperation("根据id删除菜品")
    public Result deleteDishById(@RequestParam Long[] ids){
        log.info("获取的删除查询菜品的id信息是：{}",ids);
       dishService.deleteDishById(ids);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    public Result startorstop(@PathVariable Integer status,Long id){
        log.info("获取的删除查询菜品的id信息是：{},{}",status,id);
        dishService.updateDish(status,id);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改菜品")
    public Result update(@RequestBody DishDTO dishDTO){
        log.info("获取的菜品查询信息是：{}",dishDTO);
        dishService.update(dishDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查找菜品")
    public Result<List<Dish>> findDishByCategoryId(Long categoryId){
        log.info("获取的查询菜品的id信息是：{}",categoryId);
        List<Dish> dishById = dishService.findDishByCategoryId(categoryId);
        return Result.success(dishById);
    }





}
